package com.minutes.in.seconds.ui.event;

import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.View.OnClickListener;

import com.minutes.in.seconds.R;
import com.minutes.in.seconds.common.Constants;
import com.minutes.in.seconds.ui.screens.AddMeetingActivity;
import com.minutes.in.seconds.ui.screens.LibraryActivity;
import com.minutes.in.seconds.ui.screens.MenuBarFragment;
import com.minutes.in.seconds.ui.screens.SettingActivity;

public class MenuBarEventHandler implements OnClickListener {

	private MenuBarFragment menuBarFragment;
	
	private FragmentManager fragmentManager;
	
	public MenuBarEventHandler(MenuBarFragment menuBarFragment) {
		super();
		this.menuBarFragment = menuBarFragment;
		
		fragmentManager = menuBarFragment.getActivity().getSupportFragmentManager();
	}

	@Override
	public void onClick(View v) {
		FragmentTransaction transaction = fragmentManager.beginTransaction();
		
		switch (v.getId()) {
		case R.id.library_menu_bar:
			openLibrary(transaction);
			break;
		case R.id.add_meeting_menu_bar:
			openMeeting(transaction);
			break;
		case R.id.settings_menu_bar:
			openSetting(transaction);
			break;
		}
		
		// Commit the transaction
		transaction.commit();
	}

	private void openLibrary(FragmentTransaction transaction) {
		transaction.replace(R.id.fragment, new LibraryActivity(), Constants.SCREEN_LIBRARY);
	}

	private void openMeeting(FragmentTransaction transaction) {
		transaction.replace(R.id.fragment, new AddMeetingActivity(), Constants.SCREEN_ADD_MEETING);
	}
	
	private void openSetting(FragmentTransaction transaction) {
		transaction.replace(R.id.fragment, new SettingActivity(), Constants.SCREEN_SETTING);
	}
}
